﻿using System;

namespace K9Nano.LayIM
{
    public sealed class LayIMOptions
    {
        public string ChatHubPath { get; set; } = "/im/chathub";

        public string UserIdentifierClaimType { get; set; } = "sub";
        
        public string RoleClaimType { get; set; } = "role";

        public string ChatSessionClaimType { get; set; } = "chat_sid";

        public string ChatAppCodeClaimType { get; set; } = "chat_app";

        public string DefaultGroupName { get; set; } = "我的好友";

        public string[] AllowedImageExtensions { get; set; } = { ".jpg", ".jpeg", ".png", ".tif" };

        public string StaffRoleName { get; set; } = "staff";
        
        /// <summary>
        /// Max length of images，如：1K、2M、3G
        /// </summary>
        public string MaxImageLength { get; set; } = "10M";

        public string DefaultUserAvatar { get; set; } = "/im-static/images/default/user-avatar.png";

        public string DefaultGroupAvatar { get; set; } = "/im-static/images/default/group-avatar.png";

        public string Title { get; set; } = "在线客服";

        public long GetMaxImageLength()
        {
            var unitChar = MaxImageLength[^1];
            long unit;
            switch (unitChar)
            {
                case 'K':
                case 'k':
                    unit = 1;
                    break;
                case 'M':
                case 'm':
                    unit = 2;
                    break;
                case 'G':
                case 'g':
                    unit = 3;
                    break;
                default: throw new ArgumentOutOfRangeException();
            }

            if (long.TryParse(MaxImageLength[..^1], out var value))
            {
                return (long)(value * Math.Pow(1024L, unit));
            }
            throw new ArgumentException($"MaxLength的值{MaxImageLength}无效");
        }
    }
}